export const allGoodsMap = (parcelDetail, goodsInfo) => {
  return parcelDetail.map(item => {//全部物品信息
    // console.log(`all===>`, item)
    goodsInfo.goodsIdList.push(item.id)
    switch (item.interfaceType) {
      case 1://批次
        goodsInfo.batchNo = goodsInfo.batchNo + 1
        break
      case 2://联次
        if (item.invoiceSheet === 1) {//发票联
          goodsInfo.invoiceSheet1 = goodsInfo.invoiceSheet1 + 1
        } else {//抵扣联
          goodsInfo.invoiceSheet2 = goodsInfo.invoiceSheet2 + 1
        }
        break;
      case 3://附件
        goodsInfo.attachment = goodsInfo.attachment + 1
        break
      case 4://销货清单
        goodsInfo.salesList = goodsInfo.salesList + 1
        break
    }
  })
}

export const goodsFilter = (parcelDetail, selectedRowKeys, notSignGoods) => {
  return parcelDetail.filter((element) => {//没有勾选物品信息
    let item = selectedRowKeys.indexOf(element.id)
    if (item === -1) {
      notSignGoods.goodsIdList.push(element.id)
      // console.log(`element==>`, element)
      switch (element.interfaceType) {
        case 1://批次
          notSignGoods.batchNo = notSignGoods.batchNo + 1
          break
        case 2://联次
          if (element.invoiceSheet === 1) {//发票联
            notSignGoods.invoiceSheet1 = notSignGoods.invoiceSheet1 + 1
          } else {//抵扣联
            notSignGoods.invoiceSheet2 = notSignGoods.invoiceSheet2 + 1
          }
          break;
        case 3://附件
          notSignGoods.attachment = notSignGoods.attachment + 1
          break
        case 4://销货清单
          notSignGoods.salesList = notSignGoods.salesList + 1
          break
      }
    }
  })
}

export const conversion = (tView, bView, record, tipDetail, view, senderRole) => {//带有选择框的table
  const type = record.interfaceType
  if (senderRole && senderRole === 2) {
    if (record[tView]) {
      view.tFlag = true
      view.tInfo = tipDetail[type][tView]
      view.tRecord = record[bView]
    } else { view.tFlag = false }
    if (record[bView]) {
      view.bFlag = true
      view.bInfo = tipDetail[type][bView]
      view.bRecord = record[tView]
    } else { view.bFlag = false }
  } else {
    if (record[tView]) {
      view.tFlag = true
      view.tInfo = tipDetail[type][tView]
      view.tRecord = record[tView]
    } else { view.tFlag = false }
    if (record[bView]) {
      view.bFlag = true
      view.bInfo = tipDetail[type][bView]
      view.bRecord = record[bView]
    } else { view.bFlag = false }
  }
}

export const formatMyCurrency = (number, decimals, spliter, dot) => {//number:格式化的数字，decimals:要保留几位小数,spliter：默认','，dot：默认'.'
  number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
  var n = !isFinite(+number) ? 0 : +number;//判断是否是无穷数，不是无穷数n赋值为0
  var prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
  var sep = (typeof spliter === 'undefined') ? ',' : spliter;
  var dec = (typeof dot === 'undefined') ? '.' : dot;
  var s = '';
  var toFixedFix = function (n, prec) {
    var k = Math.pow(10, prec);
    return '' + Math.round(n * k) / k;
  };
  s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
  if (s[0].length > 3) {
    s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
  }
  if ((s[1] || '').length < prec) {
    s[1] = s[1] || '';
    s[1] += new Array(prec - s[1].length + 1).join('0');
  }
  return s.join(dec);
}
